type money={
    theme:string,
    note:string,
    money:number,
}
type value={
    [date:string]:money;
}
const useMoney=()=>{
    let getMoney = ()=>{
        let a:Array<value> = JSON.parse(localStorage.getItem('money')||'[]')
        return a
    }
    let addMoney =(date:string,val:money|undefined)=>{
        if(val===undefined){
            return
        }else{
            let a:value={[date]:val}
            let b = getMoney()
            b.push(a)
            localStorage.setItem('money',JSON.stringify(b))
            window.alert('添加成功')
        }
    }
    let rmMoney =(index:number)=>{
        let a =getMoney()
        a.splice(index,1)
        localStorage.setItem('money',JSON.stringify(a))
        window.alert('删除成功')
    }
    
    return{addMoney,rmMoney,getMoney}
}

export default useMoney